<admintpl file="header"/></head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:U('Examine/loan_no_due')}">贷款未到期列表</a></li>
        <li class="active"><a>提前审核</a></li>
    </ul>
    <form class="form-horizontal js-ajax-form" method="post">
        <fieldset>
            <div class="tabbable">
                <div class="tab-content">
                    <fieldset>
                        <div class="control-group">
                            <label class="control-label">姓名</label>
                            <div class="controls">
                                <php>$ds=array('0'=>'<span style="color:red">未认证</span>','1'=>'<span style="color:green">已认证</span>','2'=>'<span style="color:red">认证未通过</span>','3'=>'<span style="color:red">暂时不需要</span>')</php>
                                <label class="control-label" style="width:auto">{$order.name}&nbsp&nbsp&nbsp&nbsp{$ds[$order['account_status']]}</label>
                                <input type="hidden" name="options[id]" value="{$order.id}">
                                <input type="hidden" name="options[user_id]" value="{$order.user_id}">
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">手机号码</label>
                            <div class="controls">
                                <label class="control-label" style="width:auto">{$order.mobile}</label>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">银行卡号</label>
                            <div class="controls">
                                <label class="control-label" style="width:auto">{$order.bank}：{$order.silver_card}&nbsp&nbsp&nbsp&nbsp预留手机号码&nbsp&nbsp{$order.silver_number}</label>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">借款金额</label>
                            <div class="controls">
                                <label class="control-label" style="width:auto">{$order.amount}元</label>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">借款天数</label>
                            <div class="controls">
                                <label class="control-label" style="width:auto">{$order.loan_day}天</label>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">放款日</label>
                            <div class="controls">
                                <label class="control-label" style="width:auto">{$order.loan_time}</label>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">分期数</label>
                            <div class="controls">
                                <label class="control-label" style="width:auto">{$order.stages}期</label>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">咨询费</label>
                            <div class="controls">
                                <label class="control-label" style="width:auto">{$order.interest}元</label>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">审核费</label>
                            <div class="controls">
                                <label class="control-label" style="width:auto">{$order.examine}元</label></div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">顾问费</label>
                            <div class="controls">
                                <label class="control-label" style="width:auto">{$order.consulting}元</label></div>
                        </div>
						<div class="control-group">
							<label class="control-label">保证金</label>
							<div class="controls"><label class="control-label" style="width:auto">{$order['bond']['bond_amount']|default=0}元</label>
							<if condition="$order['bond']['bond_amount']">
								<if condition="$order['bond']['is_back'] eq 1">
								已还
								<else/>
								未还
								</if>
							</if>
							</div>
						</div>
                        <div class="control-group">
                            <label class="control-label">到期应还</label>
                            <div class="controls">
                                <label class="control-label" style="width:auto">{$order.loan_amount}元</label></div>
                        </div>
                        <br/>
                        <div class="control-group">
                            <label class="control-label">分期详情</label>
                            <div class="controls">
                                <label class="control-label" style="width:auto">
                                    <!--<table border="1" style='text-align:center;width:800px' cellpadding='10px'>-->
                                    <table class="table table-bordered">
                                        <tr>
                                            <th>期数</th>
                                            <th>到期时间</th>
                                            <th>借款状态</th>
                                            <th>分期金额</th>
                                            <th>审核操作</th>
                                        </tr>
                                        <php>$stu_type=array('1'=>'借款中','2'=>'已还款','3'=>'逾期','4'=>'已到期','5'=>'审核中','6'=>'审核不通过','7'=>'驳回','8'=>'放款成功','9'=>'放款不成功','10'=>'待放款')</php>
                                        <php>
                                            //取出最小的未到期子订单ID（分期数最小的订单ID）
                                            $yu_sub = [];
                                            foreach($sub as $v){
                                                if($v['status'] == 1){
                                                    $stages = substr($v['stages'],0,1);
                                                    $yu_sub[] = ['id'=>$v['id'],'stages'=>$stages];
                                                }
                                            }
                                            array_multisort(array_column($yu_sub,'stages'),SORT_ASC,$yu_sub);//用分期数排序
                                            //取第一个（最小分期的逾期订单ID）
                                            $min_yu_id = $yu_sub[0]['id'];
                                        </php>
                                        <foreach name="sub" item="vo">
                                            <tr>
                                                <php>$stag=substr($vo['stages'], 1);$stages=substr($vo['stages'],0, 1);</php>
                                                <td>第{$stages}期
                                                    <if condition="$stag">第{$stag}次续期
                                                    </if>
                                                </td>
                                                <td>{$vo.endtime}</td>
                                                <td>{$stu_type[$vo['status']]}</td>
                                                <td>{$vo.amount}</td>
                                                <td>
                                                    <php>
                                                        //判断是不是最小的订单ID
                                                        if($min_yu_id == $vo['id']){
                                                        $isDisabled = '';
                                                        }else{
                                                        $isDisabled = ' disabled';
                                                        }
                                                    </php>
                                                    <php>$sel=$vo['status']!=2?('checked="checked"'.$isDisabled):'disabled'</php>
                                                    <span><input name="options[status][{$vo.id}]" {$sel} type="radio" value="0"/>借款中</span>&nbsp;&nbsp;&nbsp;&nbsp;
                                                    <php>$sel=$vo['status']==2?'checked="checked" disabled':$isDisabled</php>
                                                    <span><input name="options[status][{$vo.id}]" type="radio" {$sel} value="1"/>已还款</span>
                                                </td>
                                            </tr>
                                        </foreach>
                                        <tr>
                                            <td>共{$order.stages}期</td>
                                            <td>{$order.loan_day}天</td>
                                            <td>{$stu_type[$order['status']]}</td>
                                            <td>{$order.amount}</td>
                                            <td></td>
                                        </tr>
                                    </table>
                                </label>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">续期详情</label>
                            <div class="controls">
                                <label class="control-label" style="width:auto">
                                    <if condition="(empty($renewal))">
                                        暂无记录
                                        <else/>
                                        <!--<table border="1" style='text-align:center;width:800px' cellpadding='10px'>-->
                                        <table class="table table-bordered">
                                            <tr>
                                                <th>借款编号</th>
                                                <th>期数</th>
                                                <th>续期时间</th>
                                                <th>完结时间</th>
                                                <th>续期金额</th>
                                                <th>审核备注</th>
                                                <th>状态</th>
                                                <th>审核人</th>
                                            </tr>
                                            <foreach name="renewal" item="vo">
                                                <tr>
                                                    <td>{$vo.order_id}</td>
                                                    <php>$stag=substr($vo['stages'], 1);$stages=substr($vo['stages'],0, 1);</php>
                                                    <td>第{$stages}期
                                                        <if condition="$stag">第{$stag}次续期
                                                        </if>
                                                    <td>{$vo.renewal}</td>
                                                    <td>{$vo.endtime}</td>
                                                    <td>{$vo.amount}</td>
                                                    <td>{$vo.message}</td>
                                                    <td>{$vo['status']==1?'审核成功':'审核失败'}</td>
                                                    <td>{$lastuser[$vo['lastuser_id']]|default='系统'}</td>
                                                </tr>
                                            </foreach>
                                        </table>
                                    </if>
                                </label>
                            </div>
                        </div>
                        <if condition="($logs)">
                            <div class="control-group">
                                <label class="control-label">审核信息</label>
                                <div class="controls">
                                    <label class="control-label" style="width:auto">
                                        <!--<table border="1" style='text-align:center;width:800px' cellpadding='10px'>-->
                                        <table class="table table-bordered">
                                            <tr>
                                                <th>审核类型</th>
                                                <th>审核时间</th>
                                                <th>审核人</th>
                                                <th>收款人</th>
                                                <th>审核备注</th>
                                                <th>金额</th>
                                                <th>实收金额<br/>(不含逾期费)</th>
                                                <th>实收逾期费</th>
                                                <th>微信实收</th>
                                                <th>支付宝实收</th>
                                                <th>银行实收</th>
                                                <th>审核操作</th>
                                            </tr>
                                            <php>$stu_type=array('1'=>'借款中','2'=>'已还款','3'=>'逾期','4'=>'已到期','5'=>'审核中','6'=>'审核不通过','7'=>'驳回','8'=>'放款成功','9'=>'放款不成功','10'=>'待放款'); $stu_ty=array('0'=>'用户审核','1'=>'订单审核','2'=>'订单审核','3'=>'续期审核','4'=>'逾期还款(本金)','5'=>'逾期还款','6'=>'订单审核','7'=>'客户还款');
                                            </php>
                                            <foreach name="logs" item="vo">
                                                <tr>
                                                    <td>{$stu_ty[$vo['types']]}</td>
                                                    <td>{$vo.crtime}</td>
                                                    <td>{$lastuser[$vo['examine_id']]|default='系统'}</td>
                                                    <td>{$lastuser[$vo['payee']]}</td>
                                                    <td>{$vo.message}</td>
                                                    <td>{$vo.amount}</td>
                                                    <td>{$vo.real_amount|default='0.00'}</td>
                                                    <td>{$vo.overdue_amount|default='0.00'}</td>
                                                    <td>{$vo.wechat_amount}</td>
                                                    <td>{$vo.alipay_amount}</td>
                                                    <td>{$vo.bank_amount}</td>
                                                    <td>{$vo['status']?'审核成功':'审核失败'}</td>
                                                </tr>
                                            </foreach>
                                        </table>
                                    </label>
                                </div>
                            </div>
                        </if>
                        <div class="control-group">
                            <label class="control-label">用户余额</label>
                            <div class="controls">
                                <label class="control-label" style="width:auto">{$order.deposit|default=0}元</label></div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">还款时间</label>
                            <div class="controls">
                                <label class="control-label" style="width:auto">{$order.endtime}</label></div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">实收借条金额</label>
                            <div class="controls">
                                <input type="text" name="options[real_amount]" class="just_can_number" size="11"  placeholder="请输入数字" /><span style="color: #b4b4b4">&nbsp;备注：富友充值了的话这里不用填</span>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">
                                <b style="color:red;">* </b><strong>收款方式</strong>
                            </label>
                            <div class="controls">
                                <select id="pay_ways">
                                    <!--<option value="0">请选择一种收款方式</option>-->
                                    <option value="1">微信</option>
                                    <option value="2">支付宝</option>
                                    <option value="3">银行</option>
                                </select>
                                <button id="pay_add" type="button" class="btn btn-success">添加</button>
                                <button  id="pay_del" style="display: none;" type="button" class="btn btn-danger">减少</button>
                            </div>
                            <script>
                                $(function(){
                                    var wechat_amount = $("#wechat_amount");
                                    var alipay_amount = $("#alipay_amount");
                                    var bank_amount = $("#bank_amount");
                                    //增加
                                    $('#pay_add').click(function(){
                                        var storges = [1,2,3];
                                        for (var i in storges) {
                                            var obj = $('.pay_'+storges[i]);
                                            var dis = obj.css('display');
                                            if(dis === 'none'){
                                                obj.show();
                                                break;
                                            }
                                        }
                                        var pay_1 = $('.pay_'+storges[0]);
                                        var pay_2 = $('.pay_'+storges[1]);
                                        var pay_3 = $('.pay_'+storges[2]);
                                        var dis_1 = pay_1.css('display');
                                        var dis_2 = pay_2.css('display');
                                        var dis_3 = pay_3.css('display');
                                        var flag1 = (dis_1 === 'block' && dis_2 === 'block' && dis_3 === 'block');
                                        var flag2 = (dis_1 === 'none' && dis_2 === 'none' && dis_3 === 'none');
                                        var pay_del = $('#pay_del');
                                        if(true === flag1){
                                            $(this).hide();
                                            pay_del.show();
                                        }else if(false === flag1 && false === flag2){
                                            $(this).show();
                                            pay_del.show();
                                        }else if(false === flag1 && true === flag2){
                                            $(this).show();
                                            pay_del.hide();
                                        }
                                    });
                                    //减少
                                    $('#pay_del').click(function(){
                                        var storges = [3,2,1];
                                        for (var i in storges) {
                                            var obj = $('.pay_'+storges[i]);
                                            var dis = obj.css('display');
                                            if(dis === 'block'){
                                                obj.hide();
                                                obj.find('input').val('');//凡是隐藏了的，必须值也清空
                                                break;
                                            }
                                        }
                                        var pay_3 = $('.pay_'+storges[0]);
                                        var pay_2 = $('.pay_'+storges[1]);
                                        var pay_1 = $('.pay_'+storges[2]);
                                        var dis_1 = pay_1.css('display');
                                        var dis_2 = pay_2.css('display');
                                        var dis_3 = pay_3.css('display');
                                        var flag1 = (dis_1 === 'block' && dis_2 === 'block' && dis_3 === 'block');
                                        var flag2 = (dis_1 === 'none' && dis_2 === 'none' && dis_3 === 'none');
                                        var pay_add = $('#pay_add');
                                        if(true === flag1){
                                            $(this).show();
                                            pay_add.hide();
                                        }else if(false === flag1 && false === flag2){
                                            var flag3 = (dis_1 === 'block' && dis_2 === 'none' && dis_3 === 'none');
                                            if(flag3){
                                                $(this).hide();
                                                pay_add.show();
                                            }else{
                                                $(this).show();
                                                pay_add.show();
                                            }
                                        }else if(false === flag1 && true === flag2){
                                            $(this).hide();
                                            pay_add.show();
                                        }

                                    });
                                    //下拉
                                    $('#pay_ways').change(function(){
                                        $('#pay_add').show();
                                        $('#pay_del').hide();
                                        if(0 !== parseInt($(this).val())){
                                            switch(parseInt($(this).val())){
                                                case 1:
                                                    wechat_amount.show();
                                                    alipay_amount.hide();
                                                    bank_amount.hide();
                                                    alipay_amount.find('input').val('');
                                                    bank_amount.find('input').val('');
                                                    break;
                                                case 2:
                                                    wechat_amount.hide();
                                                    alipay_amount.show();
                                                    bank_amount.hide();
                                                    wechat_amount.find('input').val('');
                                                    bank_amount.find('input').val('');
                                                    break;
                                                case 3:
                                                    wechat_amount.hide();
                                                    alipay_amount.hide();
                                                    wechat_amount.find('input').val('');
                                                    alipay_amount.find('input').val('');
                                                    bank_amount.show();
                                                    break;
                                            }
                                        }else{
                                            wechat_amount.hide();
                                            alipay_amount.hide();
                                            bank_amount.hide();
                                        }
                                    });
                                });
                            </script>
                        </div>
                        <div class="control-group pay_1" id="wechat_amount" style="display: block;">
                            <label class="control-label">微信实收</label>
                            <div class="controls">
                                <input type="text" name="options[wechat_amount]" class="just_can_number" size="11"  placeholder="请输入数字" />
                            </div>
                        </div>
                        <div class="control-group pay_2" id="alipay_amount" style="display: none;">
                            <label class="control-label">支付宝实收</label>
                            <div class="controls">
                                <input type="text" name="options[alipay_amount]" class="just_can_number" size="11" placeholder="请输入数字" />
                            </div>
                        </div>
                        <div class="control-group pay_3" id="bank_amount" style="display: none;">
                            <label class="control-label">银行实收</label>
                            <div class="controls">
                                <input type="text" name="options[bank_amount]" class="just_can_number" size="11" placeholder="请输入数字" />
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">审核备注</label>
                            <div class="controls"><textarea name="options[messgae]" rows="4" cols="30"></textarea></div>
                        </div>
                        <div class="control-group">
                            <label class="control-label">收款人</label>
                            <div class="controls">
                                <input type="text" disabled class="disabled" size="50" value="{:session('name')}" />
                            </div>
                        </div>
                    </fieldset>
                </div>
            </div>

            <div class="form-actions">
                <button class="btn btn-primary js-ajax-submit" type="submit" data-types='1' data-action="{:U('Examine/set_exam',array('display'=>0))}" data-msg='确认已还款?' data-subcheck="true">手工确认还款</button>
                <a class="btn btn-primary js-ajax-submit" href="{:U('Examine/loan_no_due')}">返回</a>
            </div>
        </fieldset>
    </form>

</div>
<script src="__PUBLIC__/js/common.js"></script>
</body>
<script type="text/javascript">
    var ajaxForm_list = $('form.js-ajax-form');
    if (ajaxForm_list.length) {
        Wind.use('ajaxForm', 'artDialog', function () {

            $('button.js-ajax-submit').bind('click', function (e) {

                e.preventDefault();
                /*var btn = $(this).find('button.js-ajax-submit'),
                        form = $(this);*/
                var btn = $(this),
                    form = btn.parents('form.js-ajax-form');

                //批量操作 判断选项
                if (btn.data('subcheck')) {
                    btn.parent().find('span').remove();
                    var msg = btn.data('msg');
                    if (msg) {
                        art.dialog({
                            id: 'warning',
                            icon: 'warning',
                            content: btn.data('msg'),
                            cancelVal: "{:L('CLOSE')}",
                            cancel: function () {

                            },
                            button: [{
                                name: "{:L('OK')}",
                                callback: function () {
                                    ajaxSubmit(btn.data('types'));
                                },
                                focus: true
                            }]
                        });
                    } else {
                        btn.data('subcheck', false);
                        btn.click();
                    }
                    return false;
                }
            });

        });
    }

    function ajaxSubmit(type) {
        var btn = $('button.js-ajax-submit'),
            form = btn.parents('form.js-ajax-form');
        form.ajaxSubmit({
            url: type ? btn.data('action') : form.attr('action'),
            //按钮上是否自定义提交地址(多按钮情况)
            dataType: 'json',
            beforeSubmit: function (arr, $form, options) {
                var tx = type ? '审核通过' : '审核不通过';
                //按钮文案、状态修改
                btn.text(tx + '中...').attr('disabled', true).addClass('disabled');
            },
            success: function (data, statusText, xhr, $form) {
                //按钮文案、状态修改
                btn.removeClass('disabled').parent().find('span').remove();

                if (data.state === 'success') {
                    $('<span class="tips_success">' + data.info + '</span>').appendTo(btn.parent()).fadeIn('slow').delay(1000).fadeOut(function () {
                        if (data.referer) {
                            //返回带跳转地址
                            if (window.parent.art) {
                                //iframe弹出页
                                window.parent.location.href = data.referer;
                            } else {
                                window.location.href = data.referer;
                            }
                        } else {
                            if (window.parent.art) {
                                reloadPage(window.parent);
                            } else {
                                //刷新当前页
                                reloadPage(window);
                            }
                        }
                    });
                } else if (data.state === 'fail') {
                    $('<span class="tips_error">' + data.info + '</span>').appendTo(btn.parent()).fadeIn('fast');

                    btn.text('手工确认还款调整').removeProp('disabled').removeClass('disabled');
                }
            }
        });
    }
</script>
<script>
    $(function(){
        $('.just_can_number').keyup(function(){
            var obj = this;
            obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
            obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字
            obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
            obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
            obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
        });
    });
</script>
</html>